package com.fairytask.ui.guide
{
	import com.fairytask.engine.GameStage;
	import com.fairytask.engine.managers.ResManager;
	import com.fairytask.engine.resource.StaticIni;
	
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.geom.Rectangle;
	
	/**
	 * 引导指示 
	 * @author hanjy
	 */
	public class GuidePopUI extends BaseGuide
	{
		private static var instance	:GuidePopUI;
		private static var UP:int=1;				//箭头指定的
		private static var DOWN:int=2;
		private static var LEFT:int=3;
		private static var RIGHT:int=4;
		
		//皮肤类型
		private var _skinType	:int;
		
		//显示
		private var _infoBg	:MovieClip;
		private var _txtId		:String;
		
		public static function getInstance():GuidePopUI
		{
			if(instance==null)
			{
				instance	=	new GuidePopUI();
			}
			return instance;
		}
		
		public function GuidePopUI(popupUI:Boolean=false,isgood:Boolean=false)
		{
			super(popupUI);
			if(isgood)
			{
				GameStage.uiSpace.addEventListener(MouseEvent.CLICK,function(evt:MouseEvent):void{
					hide();
				});
				GameStage.sceneLayer.addEventListener(MouseEvent.CLICK,function(evt:MouseEvent):void{
					hide();
				});
			}
		}
		

		
		/**
		 * 初始化显示 
		 */
		override public function initGUI():void
		{
			_infoBg	=	ResManager.newResClass("helpBox4") as MovieClip;
			addChild(_infoBg);
			
			mouseEnabled = false;
			mouseChildren= false;
		}
		
		public function infoBGPositoin(skinType:int):void
		{
			if(_infoBg.parent)
			{
				removeChild(_infoBg);
			}
			_skinType	=	skinType;
			switch(skinType)
			{
				case UP:
					_infoBg=ResManager.newResClass("helpBox1") as MovieClip;
					break;
				case DOWN:
					_infoBg=ResManager.newResClass("helpBox2") as MovieClip;
					break;
				case LEFT:
					_infoBg=ResManager.newResClass("helpBox3") as MovieClip;
					break;
				case RIGHT:
					_infoBg=ResManager.newResClass("helpBox4") as MovieClip;
					break;
				default:
					break;
			}
			addChildAt(_infoBg,0);
			_infoBg.infoTxt.wordWrap = true;
			_infoBg.infoTxt.height = 50;
		}
		
		/**
		 * 显示提示 
		 * @param txt
		 * @param desTxt
		 * 
		 */
		override public function showGuide(txt:String, desTxt:String="",pType:int=-1):void
		{
			_txtId	=	txt;
			_infoBg.infoTxt.htmlText	=	StaticIni.getSwfLangStr(txt);
			//super.showGuide(txt,desTxt,pType);
			show(LOADLAYER);
		}
		
		/**
		 * 重设显示位置 
		 * @param pRect
		 * 
		 */
		override public function resetPos(pRect:Rectangle):void
		{
			switch(_skinType)
			{
				case UP:
					x	=	pRect.x+pRect.width/2;
					y	=	pRect.y+pRect.height;
					break;
				case DOWN:
					x	=	pRect.x+pRect.width/2;
					y	=	pRect.y;
					break;
				case LEFT:
					x	=	pRect.x+pRect.width;
					y	=	pRect.y+pRect.height/2;
					break;
				case RIGHT:
					x	=	pRect.x;
					y	=	pRect.y+pRect.height/2;
					break;
				default:
					break;
			}
		}
		
		public function get txtId():String
		{
			return _txtId;
		}
	}
}